package com.itheima.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.itheima.domain.City;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/city/*")
public class CityServlet extends BaseServlet{
    private void findAll(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //调用业务层方法
        List<City> list=cityService.findAll();

        //将list数据转成json类型的数据
        String s = new ObjectMapper().writeValueAsString(list);

        //将数据输出到页面
        resp.getWriter().write(s);
    }
}
